import { request } from '@/utils/request'
import type {
  KnowledgeParams,
  KnowledgePage,
  PageParams,
  DoctorPage,
  FollowType,
  TopDep,
  ConsultOrderPreData,
  PartialConsult,
  ConsultOrderItem,
  ConsultOrderListParams,
  ConsultOrderPage
} from '@/types/consult'

// 查询推荐/减脂/饮食健康/关注页面--百科文章列表
export const getKnowledgeList = (params: KnowledgeParams) => {
  return request<KnowledgePage>('patient/home/knowledge', 'GET', params)
}

// 查询医生列表
export const getDoctorList = (params: PageParams) => {
  return request<DoctorPage>('/home/page/doc', 'GET', params)
}

// 关注的通用接口
export const follow = (id: string, type: FollowType = 'doc') => {
  return request('/like', 'POST', { id, type })
}

// 获取所有的科室
export const getAllDep = () => request<TopDep[]>('/dep/all')

// 上传图片
export const uploadImage = (file: File) => {
  const fd = new FormData()
  fd.append('file', file)

  return request<{ id: string; url: string }>('/upload', 'POST', fd)
}

// 计算就诊信息和抵扣信息
export const getConsultOrderPre = (data: {
  type: string
  illnessType: string
}) => {
  return request<ConsultOrderPreData>('/patient/consult/order/pre', 'GET', data)
}

// 创建订单
export const createConsultOrder = (consult: PartialConsult) => {
  return request<{ id: string }>('/patient/consult/order', 'POST', consult)
}

// 获取支付链接
export const getConsultPayUrl = (data: {
  paymentMethod: 0 | 1
  orderId: string
  payCallback: string
}) => {
  return request<{ payUrl: string }>('/patient/consult/pay', 'POST', data)
}

// 获取订单详情
export const getConsultOrderDetail = (orderId: string) => {
  return request<ConsultOrderItem>('/patient/consult/order/detail', 'GET', {
    orderId
  })
}

// 根据处方ID查询处方单
export const getPrescriptionPic = (id: string) => {
  return request<{ url: string }>(`patient/consult/prescription/${id}`)
}

// 评价医生
export const evaluateConsultOrder = (data: {
  docId: string
  orderId: string
  score: number
  content: string
  anonymousFlag: number
}) => request('/patient/order/evaluate', 'POST', data)

// 问诊记录-订单列表-找医生、极速问诊、开药问诊
export const getConsultOrderList = (data: ConsultOrderListParams) => {
  return request<ConsultOrderPage>('/patient/consult/order/list', 'GET', data)
}
